<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>我的通知-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart style="background: #fff;">
	<div class="weui-header bg-blue"> 
  		<div class="weui-header-left"><a onclick="back()" href="javascript:;" class="icon icon-109 f-white">返回</a></div>
    	<h1 class="weui-header-title">通知列表</h1>
	</div>
	<div class="weui_panel weui_panel_access mt0 mb55">
	    <div class="weui_panel_bd moments" id="noticeList">
	        
	    </div>
     </div>
	
	<script id="notice-table-template" type="text/x-handlebars-template">
		{{#each rows}}
		<a href="<%=basePath %>${user.currUrl}/notices/detail/{{id}}{{#equal ${user.roleType} 0}}?sid=${user.parent.studentId}{{/equal}}" style="display: block;color: #000;">
			<div class="weui_cell moments__post weui_media_box" style="padding: 10px 5px;">
	          <div class="weui_cell_bd weui_media_bd">
	            <p class="weui_media_desc" style="color:#999;">{{dateFormat createTime}}</p>
				<div class="weui_cell_bd weui_cell_primary tz-history-nameLine" style="padding-left: 0;">
					<span class="tz-history-name">{{sender}}</span> 
					<span class="tz-history-tag f-blue">{{noticeTypeText}}</span>
				</div>
	            <!-- post内容 -->
	            <p class="weui_media_desc pt5 f-green" style="-webkit-line-clamp: 3;">{{content}}</p>
	          </div>
			</div>
		</a>
		{{/each}}
	</script>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script type="text/javascript">
	var noticeType = "${noticeType}";
	var sendeeOpenid = "${sendeeOpenid}";
	var senderId = "${senderId}";
	loadNoticeList();
	function loadNoticeList() {
		//页数 
	    var page = 0;
	    // 每页展示5个
	    var size =5;
	    $('.weui_panel').dropload({
	        scrollArea : window,
	        autoLoad : true,//自动加载
	        domUp : {//下拉
	            domClass   : 'dropload-up',
	            domRefresh : '<div class="dropload-refresh"><i class="icon icon-114"></i>上拉加载更多</div>',
	            domUpdate  : '<div class="dropload-load f15"><i class="icon icon-20"></i>释放更新...</div>',
	            domLoad    : '<div class="dropload-load f15"><span class="weui-loading"></span>正在加载中...</div>'
	        },
	        loadDownFn : function(me){//加载更多
		        page++;
				window.params = {
					page: page,
		  	 		rows: size,
		  	 		noticeType: noticeType,
		  	 		sendeeOpenid: sendeeOpenid,
		  	 		senderId: senderId
				};	            
		       	$.ajax({
		          	url : basePath + "/notice/page/query",
		  	 		type : "post",
		  	 		dataType : "json",
		  	 		data : window.params,
		            success: function(data){
		         		 if(data.rows.length == 0 || window.params.page*window.params.rows >= data.total) {// 如果没有数据
		                      // 锁定
		                      me.lock();
		                      // 无数据
		                      me.noData();
		                  }
	                	  loadNoticeHtml(data);
	                	  var lazyloadImg = new LazyloadImg({
				            el: '.weui-updown [data-img]', //匹配元素
				            top: 50, //元素在顶部伸出长度触发加载机制
				            right: 50, //元素在右边伸出长度触发加载机制
				            bottom: 50, //元素在底部伸出长度触发加载机制
				            left: 50, //元素在左边伸出长度触发加载机制
				            qriginal: false, // true，自动将图片剪切成默认图片的宽高；false显示图片真实宽高
				            load: function(el) {
				                el.style.cssText += '-webkit-animation: fadeIn 01s ease 0.2s 1 both;animation: fadeIn 1s ease 0.2s 1 both;';
				            },
				            error: function(el) {
				
				            }
				        });
	                      // 每次数据加载完，必须重置
	                      me.resetload();
		              },
		              error: function(xhr, type){
		              }
		          });
	        }
	    });
	}
	function loadNoticeHtml(data){
  		if(data.rows.length > 0) {
  			var myTemplate = Handlebars.compile($("#notice-table-template").html());
  			Handlebars.registerHelper("equal", function(v1,v2,options) {
  				if(v1 == v2) {
  					//满足添加继续执行
  					return options.fn(this);
  				}else {
  					//不满足条件执行{{else}}部分
  					return options.inverse(this);
  				}
  			});
  			Handlebars.registerHelper("dateFormat", function(v1) {
  				return getTime(v1, "yyyy-MM-dd hh:mm:ss");
  			});
  			$('#noticeList').append(myTemplate(data));
  		}
	}
	function paragraph() {
		$("#noticeList .moments__post").each(function(i, v) {
			//定义文本
			const paragraph = $($(this).find('.paragraph'));
			const paragraphText = paragraph.text();
			const paragraphLength = paragraph.text().length;
			//定义文章长度
			const maxParagraphLength = 80;
			//定义全文按钮
			const paragraphExtender = $($(this).find('.paragraphExtender'));
			if(paragraphExtender.hasClass('had')) return;
			paragraphExtender.addClass("had");
			paragraphExtender.unbind("click").html('全文');
			var toggleFullParagraph = false;
			
			//定义全文按钮
			if (paragraphLength < maxParagraphLength) {
			  paragraphExtender.hide();
			} else {
			  paragraph.html(paragraphText.substring(0, maxParagraphLength) + '...');
			  paragraphExtender.click(function(){
			    if (toggleFullParagraph) {
			      toggleFullParagraph = false;
			      paragraphExtender.html('全文');
			      paragraph.html(paragraphText.substring(0, maxParagraphLength) + '...');
			    } else {
			      toggleFullParagraph = true;
			      paragraphExtender.html('收起');
			      paragraph.html(paragraphText);
			    }
			  });
			};
		});
	}
	function imgClick1(thiz) {
		var obj = $(thiz.closest(".thumbnails")).find("img");
		var src = get_img(obj);
		var currSrc = thiz.children[0].src;
		var current;
		for(var i in src) {
			if(src[i] == currSrc) {
				current = i;
				break;
			}
		}
		img_preview(src[current], src);
	}
	function img_preview(current, urls){
        if(!current || urls.length == 0){
	        return ;
        }

        WeixinJSBridge.invoke('imagePreview', { 
            'current': current,
            'urls': urls
        }); 
	}
	function get_img(obj){
		var m = [];
		for(var i=0; i<obj.length; i++){
			m[i] = obj[i].src;
		}
		return m;
	}
</script>
</html>